﻿#region MIT Licence
/*
 * Copyright (C) 2014 PdfCreative
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software 
 * and associated documentation files (the "Software"), to deal in the Software without restriction, 
 * including without limitation the rights to use, copy, modify, merge, publish, distribute, 
 * sublicense, and/or sell copies of the Software, and to permit persons to whom 
 * the Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included 
 * in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 
 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE 
 * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
#endregion

using System;
using System.Collections.Generic;
using System.Text;

namespace PdfCreative.Pdf.Graphics.PathElements
{
    /// <summary>
    /// The PathElement class is the base class of all path element classes. It is an abstract class so it cannot be used directly.
    /// </summary>
    internal abstract class PathElement
    {
        // Private fields
        // ==============
        #region Private fields
        private float[] _parameters;
        #endregion



        // Public properties
        // =================
        #region Public properties
        /// <summary>
        /// Retrieves the parameters of this path element.
        /// </summary>
        public float[] Parameters
        {
            get { return _parameters; }
        }
        #endregion



        // Public methods
        // ==============
        #region Public methods
        /// <summary>
        /// Renders the PathElement onto the specified graphics instance.
        /// </summary>
        /// <param name="g">The graphics instance to render onto.</param>
        public abstract void Render(Graphics g);
        #endregion



        // Base class overrides
        // ====================
        #region Base class overrides
        /// <summary>
        /// Retrieves the string representation of this path element.
        /// </summary>
        /// <returns>The string representation</returns>
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("{");
            foreach (float param in _parameters) sb.AppendFormat(" {0:F2}", param);
            sb.Append("}");
            
            return sb.ToString();
        }
        #endregion



        // Public constructor
        // ==================
        #region protected constructor
        /// <summary>
        /// Constructs a new PathElement instance with the specified parameters.
        /// </summary>
        /// <param name="parameters">The parameters of this pathElement.</param>
        protected PathElement(params float[] parameters)
        {
            _parameters = new float[parameters.Length];

            Array.Copy(parameters, _parameters, parameters.Length);
        }
        #endregion

    } // PathElement class
}
